<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    //第一种方法
    //冒泡排序
    var array = [3,78,45,1,0];
     var temp = 0;
     for (var i = 0; i < array.length; i++)
     {
     for (var j = 0; j < array.length - i; j++)//
     {
     if (array[j] > array[j + 1])
     {
     temp = array[j + 1];//c=a
     array[j + 1] = array[j];//a=b
     array[j] = temp;//b=c
     }
     }
     }
     document.write(array);

    //第二种方法
    //选择排序
    //功能实现换位置
    function swap (arr,i,j) {
        var temp=arr[i];
        arr[i]=arr[j];
        arr[j]=temp;
    }
    function add1 (arr) {
        for (var i = 0; i < arr.length-1; i++) {
            for (var j = i+1; j< arr.length; j++) {
                if (arr[i]>arr[j]) {
                    swap(arr,i,j)
                }
            }
        }
        return arr;
    }
    console.log(add1([1,2,452,3,65,3,2,0,6,434,678,213]))




</script>
</body>
</html>